Mattermost Application Deploy Using Nginx on AWS, Step by Step Guide
Week Of: 2022-11-06
2022-11-06
About Mattermost
Mattermost offers a purpose-built collaboration platform designed for development workflows. The platform helps my team plan, organize, and run software development projects, while seamlessly integrating with communication and collaboration tools.more aboud Mattermost
Disclaimer & assumptions
- There is endless best practices on managing servers security in general and specifically AWS services. here I have focused on the easiest configuration with the lowest risk as I see it.
- The guide is writen with an assumption that:
- You already have AWS active account.
- The guide has writen using the AWS' region staying in Frankfurt (Which is the closest site to Israel) so this may differ from AWS-region to another (like the location of the buttons on the screen and etc.)
- You own a domain name.
- Parts of this guide (Mainly in the parts concerning the host configuration) is based on the official Mattermost's guide
AWS Intance configuration
- In your AWS account go to the EC2 console
- Click on Instances
- Launch instances button
- Fill up the Instance Name
- Don't need to change the defaults (Free tier eligible) in the sections:
- Application and OS Images
- Instance type
- In the section Key pair, click on "Create new key pair"
- In the "Create key pair" window, give the SSH name(e.g. "myssh").
The default attribute should remain as is - Key pair type=RSA Private key file format=.pem - Click on Create key pair
- The .pem file will be automatically downloaded.
- In the Network settingsCheck section, check the box Allow HTTPS traffic from the internet
- (recommanded if you've a static IP address) In the Network settingsCheck open the list next to Allow SSH traffic from and chose the value My IP
- Finally, click on Launch instance button located at the bottom of the page.
You'll get a Success massege with a link to your new instance. click on the link.
Allocation of static IP
- On the left menu, of the EC2 console that opened, under the section Network & Security, click on the menu Elastic IPs
- Allocate Elastic IP adress
- Click on Allocate button located at the bottom of the page.
You'll be returned to the Elastic IP addresses and will see your new IP adress. - check this line, and open the Action menu
- Associate Elastic IP adress
- In the opened window, Click on the Instances field, and from the list choose your instnace.
- In the Private IP Adress choose one of your available IPs.
- Click Associate
SSH connect to the instance
- Open CMD / Terminal and navigate to the folder containing the .pem file, that has been downloaded (using CD)
- Type the following command:
ssh -i <pem file name> <public IP / DNS>
For example:
ssh -i ec2.pem ec2-user@18.205.46.80
- You will then be asked "Are you sure... (yes/no)", Obviously type the answer - yes
You will be connected to your instance.
Install Docker & Docker-compose
Docker
sudo yum install docker
Approve the installation.
Start the Docker service:
sudo systemctl start docker
Verify that the installation was successful by viewing version information:
docker version
Docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.28.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Set permissions so that the docker-compose
command is executable:
sudo chmod +x /usr/local/bin/docker-compose
Now, the docker-compose is staying in the /usr/local/bin
which is not on the PATH
. To fix it, create a symbolic link:
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
Verify that the installation was successful by viewing version information:
docker-compose --version
Git
sudo yum install git
Verify that the installation was successful by viewing version information:
git version
Deploy Mattermost on Docker
- In a opened terminal window, clone the repository and enter the directory.
git clone https://github.com/mattermost/docker
cd docker
- Create your
.env
file by copying and adjusting theenv.example
file.
cp env.example .env
- Before the next step, if you own domain name, add a record to your DNS:
Type: A
Name: <sub.domain.name>
Value: <Your public IP address>
TTL: 3600
You have to verify the completion of this process before you'll move to the next step.
you can check it easily with DNS Checker tool
4. Edit the DOMAIN
value in the .env
file to correspond to the domain for your Mattermost server.
Edit the .env file:
nano .env
When you'll finish, type Ctrl+s
then Ctrl+x
to exit the editor.
- Create the required directories and set their permissions.
mkdir -p ./volumes/app/mattermost/{config,data,logs,plugins,client/plugins,bleve-indexes}
sudo chown -R 2000:2000 ./volumes/app/mattermost
TLS Configuration
Configure TLS for NGINX (optional). If you’re not using the included NGINX reverse proxy, you can skip this step.
If you need to create a new certificate and key:
bash scripts/issue-certificate.sh -d <YOUR_MM_DOMAIN> -o ${PWD}/certs
To include the certificate and key, uncomment the following lines in your .env
file and ensure they point to the appropriate files.
- CERT_PATH=./certs/etc/letsencrypt/live/${DOMAIN}/fullchain.pem
- KEY_PATH=./certs/etc/letsencrypt/live/${DOMAIN}/privkey.pem
If you're using a pre-existing certificate and key:
mkdir -p ./volumes/web/cert
cp <PATH-TO-PRE-EXISTING-CERT>.pem ./volumes/web/cert/cert.pem
cp <PATH-TO-PRE-EXISTING-KEY>.pem ./volumes/web/cert/key-no-password.pem
Verify keys path
To include the certificate and key, ensure the following variables in your .env
file points to the appropriate files.
CERT_PATH=./volumes/web/cert/cert.pem
KEY_PATH=./volumes/web/cert/key-no-password.pem
Deploy Mattermost.
Without using the included NGINX:
sudo docker-compose -f docker-compose.yml -f docker-compose.without-nginx.yml up -d
To access your new Mattermost deployment, navigate to http://<YOUR_MM_DOMAIN>:8065/
in your browser.
To shut down your deployment:
sudo docker-compose -f docker-compose.yml -f docker-compose.without-nginx.yml down
Using the included NGINX:
sudo docker-compose -f docker-compose.yml -f docker-compose.nginx.yml up -d
To access your new Mattermost deployment via HTTPS, navigate to https://<YOUR_MM_DOMAIN>/
in your browser.
To shut down your deployment:
sudo docker-compose -f docker-compose.yml -f docker-compose.nginx.yml down
Finally
Congrulations! you've finfshed configuring your Mattermost system.
Now you can create your first Mattermost System Admin user, invite more users, and explore the Mattermost platform.
Maintenance
Renew SSL Certificate
Refer to the guide here: Renew SSL certificate of the mattermost
Upgrade from mattermost-docker
For an in-depth guide to upgrading from the deprecated mattermost-docker repository, please refer to this document. For additional help pr questions, please refer to this issue.
Installing a different version of Mattermost
-
Shut down your deployment.
-
Run
git pull
to fetch any recent changes to the repository, paying attention to any potentialenv.example
changes. -
Adjust the
MATTERMOST_IMAGE_TAG
in the.env
file to point your desired [enterprise](https://docs.mattermost.com/install/(https://hub.docker.com/r/mattermost/mattermost-enterprise-edition/tags?page=1&ordering=last_updated) or team image version. -
Redeploy Mattermost.